package com.armincl.vmanga;

import com.actionbarsherlock.app.ActionBar;
import com.actionbarsherlock.app.SherlockFragmentActivity;


import com.actionbarsherlock.app.ActionBar.Tab;
import com.actionbarsherlock.app.ActionBar.TabListener;
import com.armincl.vmanga.start.StartPagerAdapter;

import android.support.v4.app.FragmentTransaction;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.os.Bundle;

public class VMangaStartActivity extends SherlockFragmentActivity implements TabListener, OnPageChangeListener{
	private ActionBar AB;
	private ViewPager VP;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_vmanga_start);
		
		VP = (ViewPager)findViewById(R.id.mainPager);
		StartPagerAdapter SPA = new StartPagerAdapter(getSupportFragmentManager());
		VP.setAdapter(SPA);
		
		AB = getSupportActionBar();
		
		AB.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
		//AB.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_HOME);
		//AB.setDisplayOptions(0, ActionBar.DISPLAY_SHOW_TITLE);
		
		Tab sampleTab = AB.newTab()
			    .setText("TAB1")
			    .setTag("TAB1")
			    .setTabListener(this);
		
		Tab sampleTab2 = AB.newTab()
			    .setText("TAB2")
			    .setTag("TAB2")
			    .setTabListener(this);
		
		AB.addTab(sampleTab);
		AB.addTab(sampleTab2);
		
		VP.setOnPageChangeListener(this);
		
	}
	
	@Override
	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		
		final int tabPosition = tab.getPosition();
		if(tab!=null)
		VP.setCurrentItem(tabPosition);
	}
	
	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub
		
	}
	@Override
	public void onTabReselected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onPageScrollStateChanged(int arg0) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onPageSelected(int position) {
		AB.getTabAt(position).select();	
	}
}
